package com.woniuxy.business.service.impl;

import com.woniuxy.business.mapper.CollateralMapper;
import com.woniuxy.business.service.CollateralService;
import com.woniuxy.entity.Collateral;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 担保物的service接口实现
 */
@Service
public class CollateralServiceImpl implements CollateralService {
    @Resource
    private CollateralMapper collateralMapper;

    //添加担保物
    @Override
    public void addCollateral(Collateral collateral) {
        collateralMapper.insertCollateral(collateral);
    }

    //根据担保物的编号删除担保物
    @Override
    public void removeCollateral(String collateral_num) {
        collateralMapper.deleteCollateral(collateral_num);
    }

    //条件查询+分页
    @Override
    public List<Collateral> getCollateralByPage(String collateral_num, String collateral_type, int pageIndex, int pageSize) {
        return collateralMapper.selectCollateralByPage(collateral_num, collateral_type,
                pageIndex, pageSize);
    }

    //根据担保物的编号查找担保物
    @Override
    public Collateral getCollateralByCollateralNum(String collateral_num) {
        return collateralMapper.selectCollateralByCollateralNum(collateral_num);
    }

    @Override
    public Set<String> getType() {
        Set<String> types = new HashSet<>();
        List<Collateral> collaterals = collateralMapper.selectCollateralType();
       for(Collateral collateral : collaterals){
           types.add(collateral.getCollateral_type());
       }
        return types;
    }
}
